package cn.iocoder.yudao.module.handguard.service.applicationrecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.module.handguard.controller.admin.client.vo.UserResultVO;
import cn.iocoder.yudao.module.handguard.controller.admin.order.vo.OrderUserRespVO;
import cn.iocoder.yudao.module.handguard.controller.admin.product.vo.ProductBaseVO;
import cn.iocoder.yudao.module.handguard.controller.admin.product.vo.ProductRespVO;
import cn.iocoder.yudao.module.handguard.controller.admin.productaccesspercentage.vo.PercentageVO;
import cn.iocoder.yudao.module.handguard.controller.admin.userdb.vo.UserRoleListVO;
import cn.iocoder.yudao.module.handguard.controller.app.carrecord.vo.CarRecordBaseVO;
import cn.iocoder.yudao.module.handguard.controller.app.orderprocessrecord.vo.OrderProcessRecordRespVO;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.OrdersInfoResVo;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.OrdersResVo;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.TJOrderResVo;
import cn.iocoder.yudao.module.handguard.controller.app.processrecord.vo.ProcessRecordRespVO;
import cn.iocoder.yudao.module.handguard.controller.app.user.vo.UserBaseVO;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable7.vo.UserBaseTable7BaseVO;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable7.vo.UserBaseTable7RespVO;
import cn.iocoder.yudao.module.handguard.convert.orderprocessrecord.OrderProcessRecordConvert;
import cn.iocoder.yudao.module.handguard.convert.processrecord.ProcessRecordConvert;
import cn.iocoder.yudao.module.handguard.convert.productaccessrecord.ProductAccessRecordConvert;
import cn.iocoder.yudao.module.handguard.convert.userbasetable1.UserBaseTable1Convert;
import cn.iocoder.yudao.module.handguard.convert.userbasetable7.UserBaseTable7Convert;
import cn.iocoder.yudao.module.handguard.dal.dataobject.applicationdeductrecord.ApplicationDeductRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.carrecord.CarRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.order.OrderDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.orderprocessrecord.OrderProcessRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.processrecord.ProcessRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.product.ProductDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.productaccesspercentage.ProductAccessPercentageDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.productaccessrecord.ProductAccessRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.publicitytype.PublicityTypeDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.user.UserDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable1.UserBaseTable1DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable10.UserBaseTable10DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable11.UserBaseTable11DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable12.UserBaseTable12DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable13.UserBaseTable13DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable14.UserBaseTable14DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable15.UserBaseTable15DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable16.UserBaseTable16DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable2.UserBaseTable2DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable3.UserBaseTable3DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable4.UserBaseTable4DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable5.UserBaseTable5DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable6.UserBaseTable6DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable7.UserBaseTable7DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable8.UserBaseTable8DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable9.UserBaseTable9DO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userfollowup.UserFollowUpDO;
import cn.iocoder.yudao.module.handguard.dal.mysql.applicationdeductrecord.ApplicationDeductRecordMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.carrecord.CarRecordMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.order.OrderMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.orderprocessrecord.OrderProcessRecordMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.processrecord.ProcessRecordMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.product.ProductMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.publicitytype.PublicityTypeMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.user.MiniUserMapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable1.UserBaseTable1Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable10.UserBaseTable10Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable11.UserBaseTable11Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable12.UserBaseTable12Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable13.UserBaseTable13Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable14.UserBaseTable14Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable15.UserBaseTable15Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable16.UserBaseTable16Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable2.UserBaseTable2Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable3.UserBaseTable3Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable4.UserBaseTable4Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable5.UserBaseTable5Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable6.UserBaseTable6Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable7.UserBaseTable7Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable8.UserBaseTable8Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable9.UserBaseTable9Mapper;
import cn.iocoder.yudao.module.handguard.dal.mysql.userfollowup.UserFollowUpMapper;
import cn.iocoder.yudao.module.handguard.enums.OrderFlowEnum;
import cn.iocoder.yudao.module.handguard.enums.OrderStatusEnum;
import cn.iocoder.yudao.module.handguard.service.applicationdeductrecord.ApplicationDeductRecordService;
import cn.iocoder.yudao.module.handguard.service.product.ProductService;
import cn.iocoder.yudao.module.handguard.service.productaccesspercentage.ProductAccessPercentageService;
import cn.iocoder.yudao.module.handguard.service.productaccessrecord.ProductAccessRecordService;
import cn.iocoder.yudao.module.handguard.service.userfollowup.UserFollowUpService;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;

import java.math.BigDecimal;
import java.sql.Array;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

import cn.iocoder.yudao.module.handguard.controller.app.applicationrecord.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.applicationrecord.ApplicationRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.applicationrecord.ApplicationRecordConvert;
import cn.iocoder.yudao.module.handguard.dal.mysql.applicationrecord.ApplicationRecordMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 用户申请贷款表（申请通过创建订单） Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ApplicationRecordServiceImpl implements ApplicationRecordService {

    @Resource
    private ApplicationDeductRecordService deductRecordService;

    @Resource
    private ProductAccessPercentageService percentageService;

    @Resource
    private ApplicationRecordMapper applicationRecordMapper;

    @Resource
    private OrderProcessRecordMapper orderProcessRecordMapper;

    @Resource
    private ProductService productService;


    @Resource
    private UserFollowUpMapper followUpMapper;

    @Resource
    private PublicityTypeMapper publicityTypeMapper;

    @Resource
    private ProcessRecordMapper processRecordMapper;

    @Resource
    private CarRecordMapper carRecordMapper;

    @Resource
    private OrderMapper orderMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private MiniUserMapper userMapper;

    @Resource
    private ProductAccessRecordService productAccessRecordService;

    @Resource
    private ApplicationDeductRecordMapper deductRecordMapper;

    @Resource
    private UserBaseTable1Mapper userBaseTable1Mapper;

    @Resource
    private UserBaseTable2Mapper userBaseTable2Mapper;

    @Resource
    private UserBaseTable3Mapper userBaseTable3Mapper;

    @Resource
    private UserBaseTable4Mapper userBaseTable4Mapper;

    @Resource
    private UserBaseTable5Mapper userBaseTable5Mapper;

    @Resource
    private UserBaseTable6Mapper userBaseTable6Mapper;

    @Resource
    private UserBaseTable7Mapper userBaseTable7Mapper;

    @Resource
    private UserBaseTable8Mapper userBaseTable8Mapper;

    @Resource
    private UserBaseTable9Mapper userBaseTable9Mapper;

    @Resource
    private UserBaseTable10Mapper userBaseTable10Mapper;

    @Resource
    private UserBaseTable11Mapper userBaseTable11Mapper;

    @Resource
    private UserBaseTable12Mapper userBaseTable12Mapper;

    @Resource
    private UserBaseTable13Mapper userBaseTable13Mapper;

    @Resource
    private UserBaseTable14Mapper userBaseTable14Mapper;

    @Resource
    private UserBaseTable15Mapper userBaseTable15Mapper;

    @Resource
    private UserBaseTable16Mapper userBaseTable16Mapper;

    @Override
    public Long createApplicationRecord(ApplicationRecordCreateReqVO createReqVO) {
        // 插入
        ApplicationRecordDO applicationRecord = ApplicationRecordConvert.INSTANCE.convert(createReqVO);
        applicationRecordMapper.insert(applicationRecord);
        // 返回
        return applicationRecord.getId();
    }

    @Override
    public void updateApplicationRecord(ApplicationRecordUpdateReqVO updateReqVO) {
        // 校验存在
        validateApplicationRecordExists(updateReqVO.getId());
        // 更新
        ApplicationRecordDO updateObj = ApplicationRecordConvert.INSTANCE.convert(updateReqVO);
        applicationRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteApplicationRecord(Long id) {
        // 校验存在
        validateApplicationRecordExists(id);
        // 删除
        applicationRecordMapper.deleteById(id);
    }

    private void validateApplicationRecordExists(Long id) {
        if (applicationRecordMapper.selectById(id) == null) {
            throw exception(APPLICATION_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public ApplicationRecordDO getApplicationRecord(Long id) {
        return applicationRecordMapper.selectById(id);
    }

    @Override
    public List<ApplicationRecordRespVO> getApplicationRecordListByUserId(Long id, String status) {
        List<ApplicationRecordRespVO> respVOList = new ArrayList<>();
        LambdaQueryWrapper<ApplicationRecordDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApplicationRecordDO::getUserId, id);
        //queryWrapper.eq(ApplicationRecordDO::getApplyState, status);
        if (status.equals("1")) { //申请中
            queryWrapper.in(ApplicationRecordDO::getApplyState, 1, 2);
        } else if (status.equals("2")) { //已完成
            queryWrapper.in(ApplicationRecordDO::getApplyState, 0, 3);
        }
        List<ApplicationRecordDO> doList = applicationRecordMapper.selectList(queryWrapper);
        if (doList.size() > 0) {
            String pName = "";
            respVOList = ApplicationRecordConvert.INSTANCE.convertList(doList);
            for (ApplicationRecordRespVO d : respVOList) {
                List<ProcessRecordRespVO> list = new ArrayList<>();
                //查询产品
                //List<ProductRespVO> productRespVOList = new ArrayList<>();
                if (d.getProductId().contains(",")) {
                    String[] str = d.getProductId().split(",");
                    for (int i = 0; i < str.length; i++) {
                        ProductRespVO productBaseVO = new ProductRespVO();
                        ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
                        //BeanUtils.copyProperties(productDO,productBaseVO);
                        //productRespVOList.add(productBaseVO);
                        pName += productDO.getProductName() + "、";
                        d.setProductImg(productDO.getProductImg());
                    }
                    d.setProductName(pName);
                } else {
                    ProductRespVO productBaseVO = new ProductRespVO();
                    ProductDO productDO = productService.getProduct(Long.valueOf(d.getProductId()));
                    d.setProductName(productDO.getProductName());
                    d.setProductImg(productDO.getProductImg());
                    //BeanUtils.copyProperties(productDO,productBaseVO);
                    //productRespVOList.add(productBaseVO);
                }

                //查询用户订单审核记录
                LambdaQueryWrapper<ProcessRecordDO> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(ProcessRecordDO::getApplicationId, d.getId());
                List<ProcessRecordDO> recordDOList = processRecordMapper.selectList(wrapper);
                list = ProcessRecordConvert.INSTANCE.convertList(recordDOList);
                d.setResList(list);

            }
        }

        return respVOList;
    }

    @Override
    public List<ApplicationRecordRespVO> getApplicationRecordList(Long id) {
        LambdaQueryWrapper<ApplicationRecordDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApplicationRecordDO::getUserId, id);
        List<ApplicationRecordDO> doList = applicationRecordMapper.selectList(queryWrapper);
        List<ApplicationRecordRespVO> respVOList = ApplicationRecordConvert.INSTANCE.convertList(doList);
        if (respVOList.size() > 0) {
            for (ApplicationRecordRespVO recordDO : respVOList) {
                //产品
                ProductDO productDO = productMapper.selectById(recordDO.getProductId());
                recordDO.setProductName(productDO.getProductName());
            }
        }
        return respVOList;
    }

    @Override
    public PageResult<ApplicationRecordDO> getApplicationRecordPage(ApplicationRecordPageReqVO pageReqVO) {
        PageResult<ApplicationRecordDO> pageResult = applicationRecordMapper.selectPage(pageReqVO);
        return pageResult;
    }

    @Override
    public PageResult<ApplyRecordDO> getApplicationRecordListPage(ApplyRecordPageReqVO pageReqVO) {
        // 设置分页参数 (当前页码, 每页显示条数)
        //        从第几条数据开始
        int firstIndex = (pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize();
        pageReqVO.setPageNo(firstIndex);

        pageReqVO.setRoleCode(0);
        pageReqVO.setAgentUserList(null);
        pageReqVO.setWarrantUserList(null);

        if (pageReqVO.getApplyTime() != null) {
            if (pageReqVO.getApplyTime().length > 0) {
                LocalDateTime[] dateTimes = pageReqVO.getApplyTime();
                // 转换为字符串
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                String startDate = dateTimes[0].format(formatter);
                String endDate = dateTimes[dateTimes.length - 1].format(formatter);
                try {
                    pageReqVO.setStartDate(DateUtils.parseDate(startDate));
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
                try {
                    pageReqVO.setEndDate(DateUtils.parseDate(endDate));
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        Long count = applicationRecordMapper.findByPageCount(pageReqVO);
        List<ApplyRecordDO> respVOList = applicationRecordMapper.findByPage(pageReqVO);
        String productNameStr = "";
        for (ApplyRecordDO respVO : respVOList) {
            if (respVO.getProductId().contains(",")) {
                String[] str = respVO.getProductId().split(",");
                for (int i = 0; i < str.length; i++) {
                    ProductRespVO productBaseVO = new ProductRespVO();
                    ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
                    BeanUtils.copyProperties(productDO, productBaseVO);
                    productNameStr += productBaseVO.getProductName() + "、";
                }
            } else {
                ProductRespVO productBaseVO = new ProductRespVO();
                ProductDO productDO = productService.getProduct(Long.valueOf(respVO.getProductId()));
                BeanUtils.copyProperties(productDO, productBaseVO);
                productNameStr = productBaseVO.getProductName();
            }
            respVO.setProductName(productNameStr);

        }
        PageResult<ApplyRecordDO> pageResult = new PageResult<>();
        if (respVOList.size()>0){
            for (ApplyRecordDO recordDO :respVOList){
                //查询提成
                ApplicationDeductRecordDO deductRecordDO = deductRecordService.getApplicationDeductRecordListByOrderId(recordDO.getId());
                //已结单直接显示
                if (deductRecordDO!=null){
                    if(recordDO.getApplyState().equals("3")){
                        recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                        recordDO.setUtils("元");
                    }else {
                        if (deductRecordDO.getDirectProfit()!=null){
                            recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                            if (deductRecordDO.getDeductType().equals("0")){
                                recordDO.setUtils("元");
                            }else {
                                recordDO.setUtils("%");
                            }
                        }
                    }
                }
            }
        }
        pageResult.setTotal(count);
        pageResult.setList(respVOList);
        return pageResult;
    }

    @Override
    public PageResult<ApplyRecordDO> getApplicationRecordListByRolePage(ApplyRecordPageReqVO pageReqVO,Long userId) {
        PageResult<ApplyRecordDO> pageResult = new PageResult<>();
        // 设置分页参数 (当前页码, 每页显示条数)
        //        从第几条数据开始
        int firstIndex = (pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize();
        pageReqVO.setPageNo(firstIndex);

        //获取当前用户角色
        UserResultVO resultVO = getUserList(userId);
        pageReqVO.setRoleCode(resultVO.getRoleCode());
        pageReqVO.setAgentUserList(resultVO.getAgentUserList());
        pageReqVO.setWarrantUserList(resultVO.getWarrantUserList());
        //获取当前用户角色
        //UserResultVO resultVO = getUserList(getLoginUser().getId());


        if (pageReqVO.getApplyTime() != null) {
            if (pageReqVO.getApplyTime().length > 0) {
                LocalDateTime[] dateTimes = pageReqVO.getApplyTime();
                // 转换为字符串
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                String startDate = dateTimes[0].format(formatter);
                String endDate = dateTimes[dateTimes.length - 1].format(formatter);
                try {
                    pageReqVO.setStartDate(DateUtils.parseDate(startDate));
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
                try {
                    pageReqVO.setEndDate(DateUtils.parseDate(endDate));
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        if (resultVO.getRoleCode()==1 && resultVO.getAgentUserList()!=null && resultVO.getWarrantUserList()!=null){
            if (resultVO.getAgentUserList().size()<=0 && resultVO.getWarrantUserList().size()<=0){
                pageResult.setTotal(0l);
                pageResult.setList(null);
                return pageResult;
            }
        }else if (resultVO.getRoleCode()==2 && resultVO.getAgentUserList()!=null){
            if (resultVO.getAgentUserList().size()<=0){
                pageResult.setTotal(0l);
                pageResult.setList(null);
                return pageResult;
            }
        }else if (resultVO.getRoleCode()==3 && resultVO.getWarrantUserList()!=null){
            if (resultVO.getWarrantUserList().size()<=0){
                pageResult.setTotal(0l);
                pageResult.setList(null);
                return pageResult;
            }
        }

        Long count = applicationRecordMapper.findByPageCount(pageReqVO);
        List<ApplyRecordDO> respVOList = applicationRecordMapper.findByPage(pageReqVO);
        String productNameStr = "";
        for (ApplyRecordDO respVO : respVOList) {
            if (respVO.getProductId().contains(",")) {
                String[] str = respVO.getProductId().split(",");
                for (int i = 0; i < str.length; i++) {
                    ProductRespVO productBaseVO = new ProductRespVO();
                    ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
                    BeanUtils.copyProperties(productDO, productBaseVO);
                    productNameStr += productBaseVO.getProductName() + "、";
                }
            } else {
                ProductRespVO productBaseVO = new ProductRespVO();
                ProductDO productDO = productService.getProduct(Long.valueOf(respVO.getProductId()));
                BeanUtils.copyProperties(productDO, productBaseVO);
                productNameStr = productBaseVO.getProductName();
            }
            respVO.setProductName(productNameStr);


            //查询提成
            ApplicationDeductRecordDO deductRecordDO = deductRecordService.getApplicationDeductRecordListByOrderId(respVO.getId());
            //已结单直接显示
            if (deductRecordDO!=null){
                if(respVO.getApplyState().equals("3")){
                    respVO.setDirectProfit(deductRecordDO.getDirectProfit());
                    respVO.setUtils("元");
                }else {
                    if (deductRecordDO.getDirectProfit()!=null){
                        respVO.setDirectProfit(deductRecordDO.getDirectProfit());
                        if (deductRecordDO.getDeductType().equals("0")){
                            respVO.setUtils("元");
                        }else {
                            respVO.setUtils("%");
                        }
                    }
                }
            }
        }



        pageResult.setTotal(count);
        pageResult.setList(respVOList);
        return pageResult;
    }

    @Override
    public List<ApplyRecordDO> getApplicationRecordList(ApplyRecordPageReqVO exportReqVO) {
        return applicationRecordMapper.selectListAll(exportReqVO);
    }

    @Override
    public List<OrdersResVo> getClientList(Long userId, Integer status) {
        //根据当前业务员id，查询当前业务员的用户是否存在订单
//        LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(UserDO::getAgentId, userId);
//        List<UserDO> userDOList = userMapper.selectList(queryWrapper);

        List<OrdersResVo> ordersResVoList = new ArrayList<>();

        List<OrdersResVo> doList = applicationRecordMapper.selectOrderByUserId(userId, status);
        if (doList.size()>0){
            //查询记录
            for (OrdersResVo resVo : doList) {
                //产品名称、金额
                String[] pId = resVo.getProductIdArr().split(",");
                String productNames = "";
                for (String pid : pId) {
                    ProductDO productDO = productMapper.selectProductById(Long.valueOf(pid));
                    if (productDO!=null){
                        productNames += productDO.getProductName() + "、";
                    }
                }
                resVo.setProductName(productNames.substring(0, productNames.length() - 1));
                //审核记录
                ProcessRecordDO processRecordDO = processRecordMapper.selectOne("application_id", resVo.getOrderId());
                if (processRecordDO != null) {
                    resVo.setCauseOfFailure(processRecordDO.getCauseOfFailure());
                }
                resVo.setOrderStatusZh(OrderStatusEnum.valueOf(resVo.getApplyState()).getStatusName());
                resVo.setOrderFlowZh(OrderFlowEnum.valueOf(resVo.getOrderStatus()).getStatusName());
            }
            ordersResVoList.addAll(doList);
        }
        return ordersResVoList;
    }

    @Override
    public OrdersInfoResVo getAdminClientInfo(Long orderId) {

        OrdersInfoResVo resVo = new OrdersInfoResVo();
        resVo.setOrderId(orderId);
        resVo.setUserType(String.valueOf(getLoginUser().getUserType()));

        ApplicationRecordDO orderDO = applicationRecordMapper.selectById(orderId);
        resVo.setApplyState(orderDO.getApplyState());
        Long userId = orderDO.getUserId();
        UserDO userDO = userMapper.getUserInfo(userId);
        if (userDO!=null){
            resVo.setMobile(userDO.getMobile());
            //用户基本信息
            UserBaseVO userBaseVO = new UserBaseVO();
            BeanUtils.copyProperties(userDO, userBaseVO);
            resVo.setUser(userBaseVO);
        }
        //产品
        List<ProductRespVO> productRespVOList = new ArrayList<>();
        String[] str = orderDO.getProductId().split(",");
        for (int i = 0; i < str.length; i++) {
            ProductRespVO productBaseVO = new ProductRespVO();
            ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
            //查询类型
            PublicityTypeDO typeDO = publicityTypeMapper.selectById(productDO.getProductType());
            BeanUtils.copyProperties(productDO, productBaseVO);
            productBaseVO.setProductTypeName(typeDO.getTypeNames());
            productBaseVO.setYgAmount(orderDO.getAmount());
            productRespVOList.add(productBaseVO);
        }
        resVo.setProduct(productRespVOList);

        //车子资产数据
        //车辆信息
        LambdaQueryWrapper<UserBaseTable7DO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBaseTable7DO::getUserId, orderDO.getUserId());
        wrapper.orderByDesc(UserBaseTable7DO::getCreateTime);
        List<UserBaseTable7DO> baseTableDO = userBaseTable7Mapper.selectList(wrapper);
        List<UserBaseTable7RespVO> carList = UserBaseTable7Convert.INSTANCE.convertList(baseTableDO);
        resVo.setCarList(carList);

        //查询审核记录
        ProcessRecordDO processRecord = processRecordMapper.selectOne(ProcessRecordDO::getApplicationId, orderId);
        ProcessRecordRespVO recordRespVO = ProcessRecordConvert.INSTANCE.convert(processRecord);
        resVo.setRecordRespVO(recordRespVO);

        //查询产品准入列表
        List<ProductAccessRecordDO> list = productAccessRecordService.getProductAccessRecordByUserIdAndOrderId(orderDO.getUserId(), orderId);
        for (ProductAccessRecordDO recordDO : list) {
            //查询提成
            ApplicationDeductRecordDO deductRecordDO = deductRecordService.getApplicationDeductRecordListByOrderId(orderId);
            if (deductRecordDO!=null){
                if (deductRecordDO.getDeductType().equals("0")){
                    recordDO.setUnits("元");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }else if (deductRecordDO.getDeductType().equals("1")){
                    recordDO.setUnits("%");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }
                recordDO.setPracticalAmount(orderDO.getPracticalAmount());
            }
        }
        resVo.setPoList(ProductAccessRecordConvert.INSTANCE.convertList(list));

        //查询提成参数
        PercentageVO percentageVO = new PercentageVO();
        if (orderDO.getApplyState().equals("3")){
            ApplicationDeductRecordDO recordDO = deductRecordService.getApplicationDeductRecordListByOrderId(orderId);
            BeanUtils.copyProperties(recordDO,percentageVO);
        }else {
            if (list.size()>0){
                //准入产品
                ProductAccessRecordDO recordDO = list.get(0);
                ProductAccessPercentageDO percentageDO = percentageService.getProductAccessPercentageByAccessId(recordDO.getAccessId());
                BeanUtils.copyProperties(percentageDO,percentageVO);
            }
        }
        resVo.setPercentage(percentageVO);

        return resVo;
    }

    @Override
    public OrdersInfoResVo getSalesmanWarrantClientInfo(Long orderId) {
        OrdersInfoResVo resVo = new OrdersInfoResVo();
        resVo.setOrderId(orderId);
        resVo.setUserType(String.valueOf(getLoginUser().getUserType()));

        ApplicationRecordDO orderDO = applicationRecordMapper.selectById(orderId);
        resVo.setApplyState(orderDO.getApplyState());
        //鉴权
        LoginUser loginUser = getLoginUser();
        if (loginUser.getUserType().equals("2")){
            if (loginUser.getId().compareTo(orderDO.getAgentId()) == 0){
            }else {
                throw exception(ILLEGAL_OPERATION_ERROR);
            }
        } else if (loginUser.getUserType().equals("3")) {
            if (loginUser.getId().compareTo(orderDO.getWarrantId()) == 0){
            }else {
                throw exception(ILLEGAL_OPERATION_ERROR);
            }
        }

        //客户信息
        Long userId = orderDO.getUserId();
        UserDO userDO = userMapper.getUserInfo(userId);
        if (userDO!=null){
            resVo.setMobile(userDO.getMobile());
            //用户基本信息
            UserBaseVO userBaseVO = new UserBaseVO();
            BeanUtils.copyProperties(userDO, userBaseVO);
            resVo.setUser(userBaseVO);
        }
        //产品
        List<ProductRespVO> productRespVOList = new ArrayList<>();
        String[] str = orderDO.getProductId().split(",");
        for (int i = 0; i < str.length; i++) {
            ProductRespVO productBaseVO = new ProductRespVO();
            ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
            //查询类型
            PublicityTypeDO typeDO = publicityTypeMapper.selectById(productDO.getProductType());
            BeanUtils.copyProperties(productDO, productBaseVO);
            productBaseVO.setProductTypeName(typeDO.getTypeNames());
            productBaseVO.setYgAmount(orderDO.getAmount());
            productRespVOList.add(productBaseVO);
        }
        resVo.setProduct(productRespVOList);

        //车子资产数据
        //车辆信息
        LambdaQueryWrapper<UserBaseTable7DO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBaseTable7DO::getUserId, orderDO.getUserId());
        wrapper.orderByDesc(UserBaseTable7DO::getCreateTime);
        List<UserBaseTable7DO> baseTableDO = userBaseTable7Mapper.selectList(wrapper);
        List<UserBaseTable7RespVO> carList = UserBaseTable7Convert.INSTANCE.convertList(baseTableDO);
        resVo.setCarList(carList);

        //查询审核记录
        ProcessRecordDO processRecord = processRecordMapper.selectOne(ProcessRecordDO::getApplicationId, orderId);
        ProcessRecordRespVO recordRespVO = ProcessRecordConvert.INSTANCE.convert(processRecord);
        resVo.setRecordRespVO(recordRespVO);

        //查询产品准入列表
        List<ProductAccessRecordDO> list = productAccessRecordService.getProductAccessRecordByUserIdAndOrderId(orderDO.getUserId(), orderId);
        for (ProductAccessRecordDO recordDO : list) {
            //查询提成
            ApplicationDeductRecordDO deductRecordDO = deductRecordService.getApplicationDeductRecordListByOrderId(orderId);
            if (deductRecordDO!=null){
                if (deductRecordDO.getDeductType().equals("0")){
                    recordDO.setUnits("元");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }else if (deductRecordDO.getDeductType().equals("1")){
                    recordDO.setUnits("%");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }
                recordDO.setPracticalAmount(orderDO.getPracticalAmount());
            }
        }
        resVo.setPoList(ProductAccessRecordConvert.INSTANCE.convertList(list));

        //查询提成参数
        PercentageVO percentageVO = new PercentageVO();
        if (orderDO.getApplyState().equals("3")){
            ApplicationDeductRecordDO recordDO = deductRecordService.getApplicationDeductRecordListByOrderId(orderId);
            BeanUtils.copyProperties(recordDO,percentageVO);
        }else {
            if (list.size()>0){
                //准入产品
                ProductAccessRecordDO recordDO = list.get(0);
                ProductAccessPercentageDO percentageDO = percentageService.getProductAccessPercentageByAccessId(recordDO.getAccessId());
                BeanUtils.copyProperties(percentageDO,percentageVO);
            }
        }
        resVo.setPercentage(percentageVO);

        return resVo;
    }

    @Override
    public OrdersInfoResVo getAppClientInfo(Long orderId) {

        OrdersInfoResVo resVo = new OrdersInfoResVo();
        resVo.setOrderId(orderId);
        resVo.setUserType(String.valueOf(getLoginUser().getUserType()));

        ApplicationRecordDO orderDO = applicationRecordMapper.selectById(orderId);
        resVo.setApplyState(orderDO.getApplyState());
        Long userId = orderDO.getUserId();
        UserDO userDO = userMapper.getUserInfo(userId);
        if (userDO!=null){
            resVo.setMobile(userDO.getMobile());
            //用户基本信息
            UserBaseVO userBaseVO = new UserBaseVO();
            BeanUtils.copyProperties(userDO, userBaseVO);
            resVo.setUser(userBaseVO);
        }
        //产品
        List<ProductRespVO> productRespVOList = new ArrayList<>();
        String[] str = orderDO.getProductId().split(",");
        for (int i = 0; i < str.length; i++) {
            ProductRespVO productBaseVO = new ProductRespVO();
            ProductDO productDO = productService.getProduct(Long.valueOf(str[i]));
            //查询类型
            PublicityTypeDO typeDO = publicityTypeMapper.selectById(productDO.getProductType());
            BeanUtils.copyProperties(productDO, productBaseVO);
            productBaseVO.setProductTypeName(typeDO.getTypeNames());
            productBaseVO.setYgAmount(orderDO.getAmount());
            productRespVOList.add(productBaseVO);
        }
        resVo.setProduct(productRespVOList);

        //车子资产数据
        //车辆信息
        LambdaQueryWrapper<UserBaseTable7DO> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserBaseTable7DO::getUserId, orderDO.getUserId());
        wrapper.orderByDesc(UserBaseTable7DO::getCreateTime);
        List<UserBaseTable7DO> baseTableDO = userBaseTable7Mapper.selectList(wrapper);
        List<UserBaseTable7RespVO> carList = UserBaseTable7Convert.INSTANCE.convertList(baseTableDO);
        resVo.setCarList(carList);

        //查询审核记录
        ProcessRecordDO processRecord = processRecordMapper.selectOne(ProcessRecordDO::getApplicationId, orderId);
        ProcessRecordRespVO recordRespVO = ProcessRecordConvert.INSTANCE.convert(processRecord);
        resVo.setRecordRespVO(recordRespVO);

        resVo.setTableId(getUserTableId(userId,String.valueOf(productRespVOList.get(0).getProductType()),orderId));

        //权证审核流程记录
        //OrderProcessRecordDO orderProcessRecordDO = orderProcessRecordMapper.selectOne(OrderProcessRecordDO::getOrderApplicationId, orderId);
        //OrderProcessRecordRespVO orderProcessRecordRespVO = OrderProcessRecordConvert.INSTANCE.convert(orderProcessRecordDO);
        //resVo.setOrderProcessRecord(orderProcessRecordRespVO);

        //查询产品准入列表
        List<ProductAccessRecordDO> list = productAccessRecordService.getProductAccessRecordByUserIdAndOrderId(orderDO.getUserId(), orderId);

        for (ProductAccessRecordDO recordDO : list) {
            //查询提成
            ApplicationDeductRecordDO deductRecordDO = deductRecordService.getApplicationDeductRecordListByOrderId(orderId);
            if (deductRecordDO!=null){
                if (deductRecordDO.getDeductType().equals("0")){
                    recordDO.setUnits("元");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }else if (deductRecordDO.getDeductType().equals("1")){
                    recordDO.setUnits("%");
                    recordDO.setSalesmanDeduct(deductRecordDO.getBusinessManagerRoyalty());
                    recordDO.setDirectProfit(deductRecordDO.getDirectProfit());
                }
                recordDO.setPracticalAmount(orderDO.getPracticalAmount());
            }
        }

        resVo.setPoList(ProductAccessRecordConvert.INSTANCE.convertList(list));


        return resVo;
    }

    @Override
    public List<OrdersResVo> getWarrantList(Long userId, Integer status) {

        //根据当前权证员idd，查询权证员的用户是否存在订单
//        LambdaQueryWrapper<UserDO> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(UserDO::getWarrantId, userId);
//        List<UserDO> userDOList = userMapper.selectList(queryWrapper);

        List<OrdersResVo> ordersResVoList = new ArrayList<>();

        List<OrdersResVo> doList = orderMapper.getOrderListByUserList(userId, status);
        //查询记录
        for (OrdersResVo resVo : doList) {
            //产品名称、金额
            String[] pId = resVo.getProductIdArr().split(",");
            String productNames = "";
            for (String pid : pId) {
                ProductDO productDO = productMapper.selectProductById(Long.valueOf(pid));
                if (productDO!=null){
                    productNames += productDO.getProductName() + "、";
                }
            }
            resVo.setProductName(productNames.substring(0, productNames.length() - 1));
            //审核记录
            ProcessRecordDO processRecordDO = processRecordMapper.selectOne("application_id", resVo.getOrderId());
            if (processRecordDO != null) {
                resVo.setCauseOfFailure(processRecordDO.getCauseOfFailure());
            }
            resVo.setOrderStatusZh(OrderStatusEnum.valueOf(resVo.getApplyState()).getStatusName());
            resVo.setOrderFlowZh(OrderFlowEnum.valueOf(resVo.getOrderStatus()).getStatusName());
        }
        ordersResVoList.addAll(doList);
        return ordersResVoList;
    }

    @Override
    public List<TJOrderResVo> getTjClientList(Long userId) {
        List<TJOrderResVo> resList = applicationRecordMapper.getTjClientList(userId);
        resList.forEach(r -> {
            if (r.getApplyState().equals(0)) {
                r.setApplyStateZh("失败");
            } else if (r.getApplyState().equals(3)) {
                r.setApplyStateZh("申请成功");
            } else {
                r.setApplyStateZh("审核中");
            }
        });
        return resList;
    }

    @Override
    public OrderUserRespVO getUserAppllicationInfo(Long id) {
        return applicationRecordMapper.getUserAppllicationInfo(id);
    }

    public UserResultVO getUserList(Long userId) {
        UserResultVO resultVO = new UserResultVO();
        UserDO userDO = userMapper.selectById(userId);
        List<String> agentUserList = new ArrayList<>();
        List<String> warrantUserList = new ArrayList<>();
        List<UserRoleListVO> list = userMapper.getUserRoleList(userId);
        for (UserRoleListVO r : list) {
            //查询所在区域所有部门
            List<String> deptList = new ArrayList<>();

            if (r.getCode().equals("financial_development")) { //财务主管
                resultVO.setRoleCode(0);
            } else if (r.getCode().equals("regional_manager")) { // 区域主管
                deptList = userMapper.getDeptIdList(userDO.getDeptId());
                agentUserList = userMapper.getDeptUserIdList(deptList,"2");
                warrantUserList = userMapper.getDeptUserIdList(deptList,"3");
                resultVO.setRoleCode(1);
                resultVO.setAgentUserList(agentUserList);
                resultVO.setWarrantUserList(warrantUserList);
                break;
            } else if (r.getCode().equals("business_supervisor")) { //业务主管
                deptList.add(String.valueOf(userDO.getDeptId()));
                agentUserList = userMapper.getDeptUserIdList(deptList,"2");
                resultVO.setRoleCode(2);
                resultVO.setAgentUserList(agentUserList);
                break;
            } else if (r.getCode().equals("warrant_supervisor") ) { //权证主管
                deptList.add(String.valueOf(userDO.getDeptId()));
                warrantUserList = userMapper.getDeptUserIdList(deptList,"3");
                resultVO.setRoleCode(3);
                resultVO.setWarrantUserList(warrantUserList);
                break;
            }else {
                resultVO.setRoleCode(4);
            }
        }
        return resultVO;
    }

    //获取对应公式表资料 id
    public Long getUserTableId(Long userId, String productTypeId,Long orderId) {
        Long tableId = 0l;
        if (productTypeId.equals("1")) {
            LambdaQueryWrapperX<UserBaseTable1DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable1DO::getUserId, userId);
            wrapperX.eq(UserBaseTable1DO::getApplicationId, orderId);
            UserBaseTable1DO tableDO = userBaseTable1Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("2")) {
            LambdaQueryWrapperX<UserBaseTable2DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable2DO::getUserId, userId);
            wrapperX.eq(UserBaseTable2DO::getApplicationId, orderId);
            UserBaseTable2DO tableDO = userBaseTable2Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("3")) {
            LambdaQueryWrapperX<UserBaseTable3DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable3DO::getUserId, userId);
            wrapperX.eq(UserBaseTable3DO::getApplicationId, orderId);
            UserBaseTable3DO tableDO = userBaseTable3Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("4")) {
            LambdaQueryWrapperX<UserBaseTable4DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable4DO::getUserId, userId);
            wrapperX.eq(UserBaseTable4DO::getApplicationId, orderId);
            UserBaseTable4DO tableDO = userBaseTable4Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("5")) {
            LambdaQueryWrapperX<UserBaseTable5DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable5DO::getUserId, userId);
            wrapperX.eq(UserBaseTable5DO::getApplicationId, orderId);
            UserBaseTable5DO tableDO = userBaseTable5Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("6")) {
            LambdaQueryWrapperX<UserBaseTable6DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable6DO::getUserId, userId);
            wrapperX.eq(UserBaseTable6DO::getApplicationId, orderId);
            UserBaseTable6DO tableDO = userBaseTable6Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("7")) {
            LambdaQueryWrapperX<UserBaseTable7DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable7DO::getUserId, userId);
            wrapperX.eq(UserBaseTable7DO::getApplicationId, orderId);
            UserBaseTable7DO tableDO = userBaseTable7Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("8")) {
            LambdaQueryWrapperX<UserBaseTable8DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable8DO::getUserId, userId);
            wrapperX.eq(UserBaseTable8DO::getApplicationId, orderId);
            UserBaseTable8DO tableDO = userBaseTable8Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("9")) {
            LambdaQueryWrapperX<UserBaseTable9DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable9DO::getUserId, userId);
            wrapperX.eq(UserBaseTable9DO::getApplicationId, orderId);
            UserBaseTable9DO tableDO = userBaseTable9Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("10")) {
            LambdaQueryWrapperX<UserBaseTable10DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable10DO::getUserId, userId);
            wrapperX.eq(UserBaseTable10DO::getApplicationId, orderId);
            UserBaseTable10DO tableDO = userBaseTable10Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("11")) {
            LambdaQueryWrapperX<UserBaseTable11DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable11DO::getUserId, userId);
            wrapperX.eq(UserBaseTable11DO::getApplicationId, orderId);
            UserBaseTable11DO tableDO = userBaseTable11Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("12")) {
            LambdaQueryWrapperX<UserBaseTable12DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable12DO::getUserId, userId);
            wrapperX.eq(UserBaseTable12DO::getApplicationId, orderId);
            UserBaseTable12DO tableDO = userBaseTable12Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("13")) {
            LambdaQueryWrapperX<UserBaseTable13DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable13DO::getUserId, userId);
            wrapperX.eq(UserBaseTable13DO::getApplicationId, orderId);
            UserBaseTable13DO tableDO = userBaseTable13Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("14")) {
            LambdaQueryWrapperX<UserBaseTable14DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable14DO::getUserId, userId);
            wrapperX.eq(UserBaseTable14DO::getApplicationId, orderId);
            UserBaseTable14DO tableDO = userBaseTable14Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("15")) {
            LambdaQueryWrapperX<UserBaseTable15DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable15DO::getUserId, userId);
            wrapperX.eq(UserBaseTable15DO::getApplicationId, orderId);
            UserBaseTable15DO tableDO = userBaseTable15Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        } else if (productTypeId.equals("16")) {
            LambdaQueryWrapperX<UserBaseTable16DO> wrapperX = new LambdaQueryWrapperX<>();
            wrapperX.eq(UserBaseTable16DO::getUserId, userId);
            wrapperX.eq(UserBaseTable16DO::getApplicationId, orderId);
            UserBaseTable16DO tableDO = userBaseTable16Mapper.selectOne(wrapperX);
            tableId = tableDO.getId();
        }
        return tableId;
    }

}
